#pragma once
#include <iostream>
#include <pthread.h>

using namespace std;

class Lazy_Mode // 懒汉模式
{
public:
    static Lazy_Mode* GetInstance()
    {
        if(ins == nullptr)
        {
            pthread_mutex_lock(&_mtx);
            if(ins == nullptr)
            {
                ins = new Lazy_Mode;
            }
            pthread_mutex_unlock(&_mtx);
        }
        return ins;
    }

    ~Lazy_Mode()
    {
        cout << "~Lazy_Mode" << endl;
        ins = nullptr;
    }

public:
    static pthread_mutex_t _mtx; // 互斥锁

private:
    Lazy_Mode()
    {
        cout << "Lazy_Mode" << endl;
    }

    Lazy_Mode(const Lazy_Mode& ins) = delete; // 拷贝构造
    Lazy_Mode& operator=(const Lazy_Mode& ins) = delete; // 赋值重载
    static Lazy_Mode* ins;
};

Lazy_Mode* Lazy_Mode::ins = nullptr;
pthread_mutex_t Lazy_Mode::_mtx = PTHREAD_MUTEX_INITIALIZER; // 互斥锁

